package com.globo.opensocial;

import org.htmlparser.nodes.TagNode;

import com.globo.opensocial.Util;
import com.globo.opensocial.tags.ForTag;
import com.globo.opensocial.tags.IfTag;
import com.globo.opensocial.tags.IncludeTag;

import junit.framework.TestCase;

public class UtilTestCase extends TestCase {
    StringBuilder tmp;
    private static final String FILE_NAME = "fileName";
    private static final String PREFIX = "prefix";
    private static final String SUFFIX = "suffix";


    protected void setUp() throws Exception {
        tmp = new StringBuilder();
    }

    public final void testCreteElementById() {
        Util.creteElementById("name", "instance", tmp);
        System.out.println(tmp.toString());
        assertEquals(tmp.toString(), "var instance = osg.E(\"name\");\n");
    }

    public final void testGetMethodNameReturnsNullForInvalidFileNameg() {
        assertNull("Filename can not start with '.'", Util.getMethodName(".invalidFileName", PREFIX, SUFFIX));
        assertNull("Filename can not start with '_'", Util.getMethodName("_invalidFileName", PREFIX, SUFFIX));
    }

    public void testGetMethodName() {
        assertEquals("prefixFileNamesuffix", Util.getMethodName(FILE_NAME, PREFIX, SUFFIX));
    }

    public final void testGetMethodNameWithSuffixDefault() {
        assertEquals("prefixFileNamePage", Util.getMethodName(FILE_NAME, PREFIX));
    }

    public final void testIsSpecialTagWhenIfTagInstance() {
        assertTrue(Util.isSpecialTag(new IfTag()));
    }

    public final void testIsSpecialTagWhenForTagInstance() {
        assertTrue(Util.isSpecialTag(new ForTag()));
    }

    public final void testIsSpecialTagWhenIncludeTagInstance() {
        assertTrue(Util.isSpecialTag(new IncludeTag()));
    }

    public void testIsSpecialTagWhenOtherNoteTagInstance() {
        assertFalse(Util.isSpecialTag(new TagNode()));
    }

    public final void testAppendInclude() {
        Util.appendInclude("template", tmp);
        System.out.println(tmp.toString());
        assertEquals(tmp.toString(), "(new osg.Template('template').append(this).show())");
    }

}
